<?php
class EnlacesController extends AppController {

	var $name = 'Enlaces';
	var $helpers = array('Html', 'Form', 'Time','Flash','Javascript');

	function index() {
		$this->Enlace->recursive = 0;
		$this->paginate['limit'] = 18;
		$this->set('enlaces', $this->paginate());

		if (isset($this->params['requested']))
		{
			$links = $this->Enlace->find('all',array('conditions'=>array('enfront'=>1)));
			return $links;
		}
	}


	function admin_index() {

	if(isset($this->params['admin']) && $this->params['admin'])
	{
			// check that a user is logged in
			    $this->check_user();
	}
		$this->layout='admin';
		$this->Enlace->recursive = 0;
		$this->set('enlaces', $this->paginate());
	}

	function admin_view($id = null) {
	if(isset($this->params['admin']) && $this->params['admin'])
	{
			// check that a user is logged in
			    $this->check_user();
	}
		$this->layout='admin';
		if (!$id) {
			$this->Session->setFlash(__('Invalid Enlace.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('enlace', $this->Enlace->read(null, $id));
	}

	function admin_add() {
	if(isset($this->params['admin']) && $this->params['admin'])
	{
			// check that a user is logged in
			    $this->check_user();
	}
		$this->layout='admin';
		if (!empty($this->data)) {
			$this->Enlace->create();
			if ($this->Enlace->save($this->data)) {
				$this->Session->setFlash(__('The Enlace has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Enlace could not be saved. Please, try again.', true));
			}
		}
	}

	function admin_edit($id = null) {
	if(isset($this->params['admin']) && $this->params['admin'])
	{
			// check that a user is logged in
			    $this->check_user();
	}
		$this->layout='admin';
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Enlace', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Enlace->save($this->data)) {
				$this->Session->setFlash(__('The Enlace has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Enlace could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Enlace->read(null, $id);
		}
	}

	function admin_delete($id = null) {
	if(isset($this->params['admin']) && $this->params['admin'])
	{
			// check that a user is logged in
			    $this->check_user();
	}
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Enlace', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Enlace->del($id)) {
			$this->Session->setFlash(__('Enlace deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>
